/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
func rob(root *TreeNode) int {
    res := backTravel(root)
    return max(res[0], res[1])
}

func backTravel(root *TreeNode) [2]int {
    // 0 偷 1 不偷
    if root == nil { // 空节点返回0
        return [2]int{0, 0}
    }
    // 后续遍历
    left := backTravel(root.Left)
    right := backTravel(root.Right)
    stealCurr := root.Val + left[1] + right[1]
    NoSteal := max(left[0], left[1]) + max(right[0], right[1])
    return [2]int{stealCurr, NoSteal}
}

func max(a, b int) int {
    if a > b {
        return a
    }
    return b
}